package com.demo.youxuanmall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.youxuanmall.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
 
@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 获取指定日期范围内的每日用户增长数据
     */
    @Select("SELECT DATE(create_time) as date, COUNT(*) as count " +
            "FROM user " +
            "WHERE create_time >= #{startDate} AND create_time <= #{endDate} " +
            "GROUP BY DATE(create_time) " +
            "ORDER BY date")
    List<Map<String, Object>> getUserGrowthByDay(@Param("startDate") String startDate, @Param("endDate") String endDate);
    
    /**
     * 获取总用户数
     */
    @Select("SELECT COUNT(*) FROM user WHERE is_deleted = 0")
    Integer getTotalUserCount();
    
    /**
     * 获取指定日期范围内的新增用户数
     */
    @Select("SELECT COUNT(*) FROM user WHERE create_time >= #{startDate} AND create_time <= #{endDate} AND is_deleted = 0")
    Integer getNewUserCount(@Param("startDate") String startDate, @Param("endDate") String endDate);
} 